package org.jdesktop.swingx.painter;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;

import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.GeoPosition;

import vnreal.ZNEW.GraphTest.SubstrateLink;
import vnreal.ZNEW.GraphTest.WorkOnPaths;
import vnreal.map.Map;
import vnreal.map.MyWaypoint;

public class LinkPainter<JXMapViewer> implements Painter<JXMapViewer>{
	@Override
    public void paint(Graphics2D g, JXMapViewer map, int w, int h) {
		g = (Graphics2D) g.create();
	    // convert from viewport to world bitmap
	    Rectangle rect = Map.mapKit.getMainMap().getViewportBounds();
	    g.translate(-rect.x, -rect.y);

	    //set the line properties
	    g.setColor(Color.RED);
	    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	    g.setStroke(new BasicStroke(2));

	    // do the drawing
	    for(SubstrateLink link : WorkOnPaths.substrateEdges) {
	    	Point2D pt1 = null;
	    	Point2D pt2 = null;
	    	for (MyWaypoint wayPoint : Map.waypoints) {
		    	GeoPosition point = wayPoint.getPosition();
		    	if(point.getLatitude() == link.src.latitude && point.getLongitude() == link.src.longitude) {
		    		pt1 = Map.mapKit.getMainMap().getTileFactory().geoToPixel(point, Map.mapKit.getMainMap().getZoom());
		    	}
		    	if(point.getLatitude() == link.dst.latitude && point.getLongitude() == link.dst.longitude) {
		    		pt2 = Map.mapKit.getMainMap().getTileFactory().geoToPixel(point, Map.mapKit.getMainMap().getZoom());
		    	}
		    }
	    	g.drawLine((int) pt1.getX(), (int) pt1.getY(), (int) pt2.getX(), (int) pt2.getY());
	    }
	}
}
